﻿import mx.utils.Delegate;
import A2.btnEffect.uBtn;

/**
 * ...
 * @author wangjun
 */

class A2.btnEffect.group.V3 {
	
	// [用法]
	// var bs=new A2.btnEffect.group.V3();
	// for循环做按钮...{
	
	//	new be(this, oo, function (evt) {
	//		trace(evt.id);
	//	});	
	// bs.push(oo);
	// }
	
	// bs.set(0) ;
	// 
	var _g:Array = [];
	var _id:Number;
	var superTop;
	function bgV3(superTop) {
		this.superTop = superTop;		
	}
	function push(btn:MovieClip) {
		this._g.push(btn);
		btn.gid = this._g.length-1;
		btn._onRelease3 = btn.onRelease;
		btn.gp = this;
		btn.onRelease = function() {
			// trace('gid '+this.gid+'\t'+this.gp._id);
			//trace(btn.cb+' '+btn.cb()+' || '+this.gid+' '+this.gp._id);
			trace('10点监视 this.gp = '+this.gp )
			trace('10点监视 this.gp.superTop = '+this.gp.superTop)
			if(this.gp.superTop!='nolimit'){
				if (this.gid == this.gp._id || btn.cb()) {
					return;
				}
			}
			// get ID        
			//
			//trace('getLastID -> '+ uBtn.getLastID(this._name));
			this._onRelease3({gid:this.gid, oid:this.gp._id,id: uBtn.getLastID(this._name), it:this});
			
			var prev = this.gp._g[this.gp._id];
			
			//trace('-------------------------------------'); 
			//trace('prev -> '+prev+'.onRollOut -> '+prev.onRollOut );
			//trace('prev -> '+prev+'._onRollOut -> '+prev._onRollOut );
			//trace('prev -> ' + prev + '._onRollOut2 -> ' + prev._onRollOut2);
			//trace('-------------------------------------');
			
			reback(prev);
			this.gp.set(this.gid);
			prev._onRollOut2();
		};
	}
	function set(id) {
		var btn:MovieClip = this._g[id];
		
		btn.onRollOver();
		this._id = id; 
				record(btn);
				del(btn); 
		/*
		for (var i in this._g ) {
			if (this._g[i] == btn) {
				btn.onRollOver();
			}else {					
				btn.onRollOut();
			}
	
		}*/
	}
	function getID() {
		return this._id;
	}
	function get id() {
		return this._id;
	}
	static function record(btn) {
		btn._onRollOut2 = btn.onRollOut;
		//trace('_onRollOut2 -> '+btn._onRollOut2)
		//btn._onRollOver2 = btn.onRollOver;
		btn._onRelease2 = btn.onRelease;
		btn._onReleaseOutside2 = btn.onReleaseOutside;
		btn._onPress2 = btn.onPress;
	}
	static function del(btn) {
		//delete btn.onRollOut;
		//delete btn.onRollOver;
		delete btn.onRelease;
		delete btn.onReleaseOutside;
		delete btn.onPress;
	}
	static function reback(btn:MovieClip) {
		//btn.onRollOut = btn._onRollOut2;
		//btn.onRollOver = btn._onRollOver2;
		btn.onRelease = btn._onRelease2;
		btn.onReleaseOutside = btn._onReleaseOutside2;
		btn.onPress = btn._onPress2;
		//trace(' --------------------------')
		//trace(' i am reback')
		//trace(btn)
		//trace(btn.onRelease)
		//trace(btn.onReleaseOutside)
		//trace(btn.onPress)
		//delete btn._onRollOut2;
		//delete btn._onRollOver2;
		delete btn._onRelease2;
		delete btn._onReleaseOutside2;
		delete btn._onPress2;
	}
}
